package com.ytjj.qmyx.admin.controller;

import com.ytjj.common.api.CommonPage;
import com.ytjj.common.api.CommonResult;
import com.ytjj.qmyx.admin.annotation.OperLog;
import com.ytjj.qmyx.admin.constants.SysLogConstants;
import com.ytjj.qmyx.admin.model.request.NavRequest;
import com.ytjj.qmyx.admin.model.response.NavResponse;
import com.ytjj.qmyx.admin.service.NavService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/nav")
public class NavController {

    @Autowired
    private NavService navService;

    @PostMapping("/list")
    public CommonResult list(@RequestBody NavRequest navRequest){
        CommonPage<NavResponse> pageList = navService.queryNavList(navRequest);
        return CommonResult.success(pageList);
    }

    @PostMapping("/insertNav")
    @OperLog(operModule = "下标导航栏模块", operDesc = "添加导航栏", operType = SysLogConstants.OPERATION_ADD)
    public CommonResult insertNav(@RequestBody NavRequest navRequest){
        int count = navService.insertNav(navRequest);
        if(count > 0){
            return CommonResult.success(count);
        } else {
            return CommonResult.failed();
        }
    }

    @PostMapping("/updateNav")
    @OperLog(operModule = "下标导航栏模块", operDesc = "修改导航栏", operType = SysLogConstants.OPERATION_UPDATE)
    public CommonResult updateNav(@RequestBody NavRequest navRequest){
        int count = navService.updateNav(navRequest);
        if(count > 0){
            return CommonResult.success(count);
        } else {
            return CommonResult.failed();
        }
    }

    @GetMapping("/deleteNav")
    @OperLog(operModule = "下标导航栏模块", operDesc = "删除导航栏", operType = SysLogConstants.OPERATION_DELETE)
    public CommonResult deleteNav(@RequestParam("id") Integer id){
        int count = navService.deleteNav(id);
        if(count > 0){
            return CommonResult.success(count);
        } else {
            return CommonResult.failed();
        }
    }

}
